<template>
  <div class="uplaodBox">
    <a-row class="head">
      <div style="cursor: pointer;" @click="goback">
        <a-icon type="left" />
        <div class="left2">返回</div>
      </div>
      <a-col class="title">
        <strong>批量导入</strong>
      </a-col>
    </a-row>
    <a-spin :spinning="uploading">
      <div class="ant-upload-select-text-box" style="padding-top: 24px">
        <a-upload ref="upload" :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload">
          <img :src="uploadImg" style="width: 139px;height: 106px" />
          <div class="ant-modal-body">
            <div style="font-size: 12px;color: #666;">
              点击添加文件或将文件拖拽到此处
            </div>
            <div style="font-size: 12px;color: #999">
              (文件大小不超过5M)
            </div>
          </div>
        </a-upload>
      </div>
    </a-spin>
    <div class="tipBox">
      <a-row style="color: #252525;font-size: 16px;font-weight: 500">
        导入提示：
      </a-row>
      <a-row>
        <a-col :span="12" style="line-height:25px;margin-top:12px">
          <div>
            1.首先下载标准模板，填写信息后再上传<span class="primary" style="cursor:pointer;margin-left:12px;" @click="download"
              >点击下载模板</span
            >
          </div>
          <div>2.姓名、身份证号为必填项，顺序可调整，但不可删除</div>
        </a-col>
      </a-row>
    </div>
    <a-modal v-model="dialogFailVisible" title="未成功名单" width="800px" @ok="handleFailClose">
      <a-table :row-key="d => d.id" :columns="columns" :data-source="Faildata" :pagination="false" />
    </a-modal>
  </div>
</template>
<script>
import UploadMixin from "xqjr-plugin-common/UploadOrExport/uploadMixin";
const mixin = new UploadMixin();
const columns = [
  {
    title: "行号",
    dataIndex: "id",
    key: "id"
  },
  {
    title: "姓名",
    dataIndex: "empName",
    key: "empName"
  },
  {
    title: "原因",
    dataIndex: "reason",
    key: "reason"
  }
];
import axios from "axios";
import qs from "qs";
import moment from "moment";
export default {
  mixins: [mixin],
  data() {
    return {
      columns,
      uploadImg: require("@/assets/img/uploadImg.png"),
      params: {
        templateName: "taxGrandTemplate.xlsx"
      },
      url: `/hr/api/v1/excel/template/download`,
      excelName: "个税累计导入模板.xlsx"
    };
  },

  created() {
    this.salaryTemplateId = this.$route.query.salaryTemplateId;
    this.month = moment().format("MM");
    this.year = moment().format("YYYY");
    const companyId = this.$store.state.hr.companyId;
    this.action = `/salary/api/v1/empTaxGrandTotals/importExcel?companyId=${companyId}&monthly=${this.month}&yearly=${this.year}&force=false`;
  },
  methods: {
    handleUploadError() {
      this.$message.warning("没有文件");
    }
    // beforeUpload(file) {
    //   if (this.fileList.length > 0) {
    //     this.$message("最多只能上传一个");
    //     return false;
    //   }
    //   this.fileList = [...this.fileList, file];
    //   if (this.fileList && this.fileList.length > 0) {
    //     const { fileList } = this;
    //     const formData = new FormData();
    //     fileList.forEach(file => {
    //       formData.append("file", file);
    //     });
    //     this.uploading = true;

    //     axios({
    //       url: this.action,
    //       method: "get",
    //       data: formData,
    //       headers: this.headers
    //     }).then(res => {
    //       this.reset();
    //       this.handleSuccess(res.data);
    //       this.uploading = false;
    //     });
    //   } else {
    //     this.reset();
    //     this.handleUploadError();
    //   }
    //   return false;
    // }
  }
};
</script>
<style lang="scss" scoped>
.primary {
  color: var(--primary);
}
.uplaodBox {
  padding-bottom: 24px;
  .head {
    .anticon-left {
      z-index: 3;
      left: 24px;
      position: absolute;
      color: #595959;
      font-size: 20px;
      margin-top: 21px;
      color: #c0c0c0;
    }
    .left2 {
      z-index: 3;
      left: 45px;
      position: absolute;
      font-size: 14px;
      cursor: pointer;
      color: #c0c0c0;
    }
    font-size: 16px;
    color: #000;
    font-weight: 500;
    text-align: center;
    line-height: 60px;
    height: 60px;
    border-bottom: 1px solid #e8e8e8;
  }
  .exportTitle {
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    color: #252525;
  }
  .left2 {
    z-index: 3;
    left: 50px;
    position: absolute;
    color: #595959;
    font-size: 14px;
  }
  .anticon-left {
    z-index: 3;
    left: 24px;
    position: absolute;
    color: #d8d8d8;
    font-size: 26px;
    margin-top: 17px;
  }
  .tipBox {
    line-height: 18px;
    background: #faf9f9;
    border-radius: 4px;
    font-size: 12px;
    color: #595959;
    margin: 0 24px;
    padding: 12px;
    height: 120px;
  }
  .ant-upload-select-text-box {
    border: 1px dashed #b8b8b8;
    background: #fff;
    margin: 24px;
    text-align: center;
    cursor: pointer;
    border-radius: 4px;
    padding: 12px;
  }
  .ant-upload-select-text-box ::v-deep .ant-upload-list {
    display: none;
  }
  .ant-upload-list-item-name {
    text-align-last: left;
  }

  .anticon-upload {
    font-size: 40px;
  }

  .ant-modal-body {
    line-height: 24px;

    em {
      color: var(--primary);
      font-style: normal;
    }
  }
}
</style>
